package com.sailfish.springbootdemo.dao.db7;

import com.sailfish.springbootdemo.common.DB7TableName;
import com.sailfish.springbootdemo.pojo.db7.TbFlowCompVplPinNumber;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface TbFlowCompVplPinNumberDao {
    @Select("<script>" +
            "select " +
            "* " +
            "from " + DB7TableName.TB_FLOW_COMP_VPL_PIN_NUMBER + " " +
            "where flow_no = #{flowNo} and flow_level = #{flowLevel}" +
            "</script>"
    )
    List<TbFlowCompVplPinNumber> getTbFlowCompVplPinNumberByFlowNo(@Param("flowNo") String flowNo,
                                                                   @Param("flowLevel") Integer flowLevel);

    @Insert("<script>" +
            "insert into " + DB7TableName.TB_FLOW_COMP_VPL_PIN_NUMBER + " " +
            "( "+
            "flow_no, " +
            "flow_level, " +
            "create_time, " +
            "create_user, " +
            "update_time, " +
            "update_user, " +
            "pad_name, " +
            "pin_number, " +
            "pin_x, " +
            "pin_y, " +
            "pkg_name, " +
            "regular_pad_length, " +
            "regular_pad_width, " +
            "drill_hole_length, " +
            "drill_hole_width, " +
            "drill_hole_tol_p, " +
            "drill_hole_tol_n, " +
            "anti_pad_size, " +
            "thermal_pad_size " +
            ")"+
            "values "+
            "<foreach collection=\"entities\" item=\"entity\" separator=\",\">" +
            "(" +
            "#{entity.flow_no}, " +
            "#{entity.flow_level}, " +
            "#{entity.create_time}, " +
            "#{entity.create_user}, " +
            "#{entity.update_time}, " +
            "#{entity.update_user}, " +
            "#{entity.pad_name}, " +
            "#{entity.pin_number}, " +
            "#{entity.pin_x}, " +
            "#{entity.pin_y}, " +
            "#{entity.pkg_name}, " +
            "#{entity.regular_pad_length}, " +
            "#{entity.regular_pad_width}, " +
            "#{entity.drill_hole_length}, " +
            "#{entity.drill_hole_width}, " +
            "#{entity.drill_hole_tol_p}, " +
            "#{entity.drill_hole_tol_n}, " +
            "#{entity.anti_pad_size}, " +
            "#{entity.thermal_pad_size} " +
            ")"+
            "</foreach>"+
            "</script>"
    )
    Integer insertTbFlowCompVplPinNumberBatch(@Param("entities") List<TbFlowCompVplPinNumber> entities);

    @Update("<script>" +
            "update " + DB7TableName.TB_FLOW_COMP_VPL_PIN_NUMBER + " " +
            "set " +
            " <if test='entity.pad_name != null'>pad_name = #{entity.pad_name},</if>" +
            " <if test='entity.pin_number != null'>pin_number = #{entity.pin_number},</if>" +
            " <if test='entity.pin_x != null'>pin_x = #{entity.pin_x},</if>" +
            " <if test='entity.pin_y != null'>pin_y = #{entity.pin_y},</if>" +
            " <if test='entity.pkg_name != null'>pkg_name = #{entity.pkg_name},</if>" +
            " <if test='entity.regular_pad_length != null'>regular_pad_length = #{entity.regular_pad_length},</if>" +
            " <if test='entity.regular_pad_width != null'>regular_pad_width = #{entity.regular_pad_width},</if>" +
            " <if test='entity.drill_hole_length != null'>drill_hole_length = #{entity.drill_hole_length},</if>" +
            " <if test='entity.drill_hole_width != null'>drill_hole_width = #{entity.drill_hole_width},</if>" +
            " <if test='entity.drill_hole_tol_p != null'>drill_hole_tol_p = #{entity.drill_hole_tol_p},</if>" +
            " <if test='entity.drill_hole_tol_n != null'>drill_hole_tol_n = #{entity.drill_hole_tol_n},</if>" +
            " <if test='entity.anti_pad_size != null'>anti_pad_size = #{entity.anti_pad_size},</if>" +
            " <if test='entity.thermal_pad_size != null'>thermal_pad_size = #{entity.thermal_pad_size},</if>" +
            " update_time = #{entity.update_time}," +
            " update_user = #{entity.update_user}" +
            " where id = #{entity.id}" +
            //"where flow_no = #{entity.flow_no} and flow_level = #{entity.flow_level}" +
            "</script>"
    )
    Integer updateTbFlowCompVplPinNumber(@Param("entity") TbFlowCompVplPinNumber entity);

    @Delete("<script>" +
            "delete from " + DB7TableName.TB_FLOW_COMP_VPL_PIN_NUMBER + " " +
            "where flow_no = #{flowNo} and flow_level = #{flowLevel}" +
            "</script>"
    )
    Integer deleteTbFlowCompVplPinNumber(@Param("flowNo") String flowNo, @Param("flowLevel") Integer flowLevel);

    @Delete("<script>" +
            "delete from " + DB7TableName.TB_FLOW_COMP_VPL_PIN_NUMBER + " " +
            "where flow_no = #{flowNo}" +
            "</script>"
    )
    Integer deleteTbFlowCompVplPinNumberByFlowNo(@Param("flowNo") String flowNo);
}
